#coding=utf-8
import requests
import json
from log import logger


class HttpHelp(object):
    #封装get方法
    @staticmethod
    def get(url,headers='',parameter=''):
        try:
            response = requests.get(url,headers=headers,params=parameter)
            #错误的请求抛出异常
            response.raise_for_status() 
            response.encode="utf-8"   
        except Exception as e:
            logger.error(e)
        return response.text
    #封装post方法
    @staticmethod
    def post(url,headers='',parameter=''):
        try:
            response = requests.post(url,headers=headers,data=parameter)
            #错误的请求抛出异常
            response.raise_for_status()
            response.encode="utf-8"  
        except Exception as e:
            logger.error(e)
        return response.text
    
def to_dict(data):
    if isinstance(data,dict):
        return data
    else:
        data=json.loads(data.encode('utf-8'))
        return data


if __name__=="__main__":
    data =HttpHelp.post("http://10.100.112.42:8083/booking/bookingService/getSN", {"Content-type": "application/json"}, json.dumps({"memberId":"181297774"}))
    print data